package com.xigua._查找;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/2612:54
 */
public class _35_搜索插入位置 {


    public static void main(String[] args) {
        searchInsert(new int[]{1,3,5,6},0);
    }

    //1 3 5 6
    public static int searchInsert(int[] nums, int target) {
        int start = 0;
        int end = nums.length-1;
        while (start<end){
            int mid = end-start>>1+start;
            if (nums[mid] == target) return mid;
            else if (nums[mid]>target) end = mid-1;
            else start = mid+1;
        }
        return  target<=nums[start] ?  start : start +1;
    }

}
